<template>
    <!-- 总容器 -->
    <div class="wrapper">
        <header>
            <i class="fa fa-angle-left" onclick="history.go(-1)"></i>
            <p>健康档案</p>
            <div></div>
        </header>
        <div class="top-ban"></div>

        <section>
            <img src="../../assets/img/report.png" />
            <ul>
                <li v-for="(item, index) in orderlist" :key="index">
                    <div class="left">
                        <i class="fa fa-file-text-o"></i>
                        <div>
                            <p>{{ new Date(item.orderdate).toISOString().substring(0, 10) }} 体检报告</p>
                            <p>{{ item.hospital.name }}</p>
                        </div>
                    </div>
                    <div
                        class="right"
                        @click="toreport(item.orderid)"
                    >
                        <i class="fa fa-angle-right"></i>
                    </div>
                </li>
                <li v-if="orderlist.length === 0">
                    <div class="no-data">
                        <i class="fa fa-exclamation-circle"></i>
                        <p>暂无体检报告</p>
                    </div>
                </li>
            </ul>
        </section>

        <div class="bottom-ban"></div>
        <tijianfooter></tijianfooter>
    </div>
</template>

<script setup>
import "../../style/css/reportlist.css";
import tijianfooter from "../../components/tijianfooter.vue";
import router from "@/router";
import {getSessionStorage} from "@/utils/common";
import {ref, onMounted} from "vue";
import axios from "axios";

const user = ref(getSessionStorage("user"));
const orderlist = ref([]);
const fetchOrderList = async () => {
    try {
        const res = await axios.post("/api/order/orderlist", {userid: user.value.userid});
        orderlist.value = res.data.data || [];
        console.log(typeof orderlist.value[0].orderdate);
    } catch (error) {
        console.error("获取订单列表失败:", error.response?.data?.message || error.message);
    }
};

onMounted(fetchOrderList);

const toreport = (id) => {
    router.push({
        path: "/report",
        query: {
            orderid: id}
    });
};
</script>

<!-- <style scoped>
header{
    width: 100%;
    height: 15.7vw;
    background-color: #FFF;

    position: fixed;
    left: 0;
    top: 0;

    display: flex;
    align-items: center;
    justify-content: space-between;

    box-sizing: border-box;
    padding: 0 3.6vw;
}
header .fa{
    font-size: 8vw;
}

/*********************** footer ***********************/
footer{
    width: 100%;
    height: 14.2vw;
    box-sizing: border-box;
    border-top: solid 1px #E9E9E9;
    background-color: #FFF;

    position: fixed;
    left: 0;
    bottom: 0;
}
footer ul{
    width: 100%;
    height: 14.2vw;
    display: flex;
    align-items: center;
    justify-content: space-around;
}
footer ul li{
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    font-size: 3vw;
    color: #999;

    user-select: none;
    cursor: pointer;
}
footer ul li .fa{
    font-size: 5vw;
}

/*********************** common样式 ***********************/
.top-ban{
    width: 100%;
    height: 15.7vw;
}
.bottom-ban{
    width: 100%;
    height: 14.2vw;
}

/*********************** section ***********************/
section{
    width: 100%;
}
section img{
    width: 100%;
    display: block;
}
section ul{
    width: 86vw;
    margin: 0 auto;
}
section ul li{
    width: 100%;
    height: 18vw;
    border-bottom: solid 1px #EEE;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
section ul li .left{
    display: flex;
    align-items: center;
}
section ul li .left i{
    font-size: 12px;
    color: #6BB9B6;
    margin-right: 3vw;
}
section ul li .left p:first-child{
    color: #555;
    font-size: 4.2vw;
    font-weight: 600;
}
section ul li .left p:last-child{
    color: #999;
    font-size: 3.2vw;
    font-weight: 600;
    margin-top: 1vw;
}
section ul li .right{
    user-select: none;
    cursor: pointer;
}
section ul li .right i{
    color: #999;
    font-size: 6vw;
    transition: transform 0.3s;
}
section ul li .right:hover i{
    transform: rotate(90deg);
}
section ul li:last-child{
    border-bottom: none;
}
section ul li .no-data{
    width: 100%;
    height: 18vw;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    font-size: 4vw;
}
section ul li .no-data i{
    font-size: 8vw;
    color: #999;
    margin-bottom: 2vw;
}
section ul li .no-data p{
    font-size: 3vw;
    color: #999;
}

</style> -->
